//
//  LDLibDefine.swift
//  DingDongZP
//
//  Created by 三秒文化 on 16/6/27.
//  Copyright © 2016年 51ledian.com. All rights reserved.
//

import Foundation
import ReactiveCocoa


struct RAC  {
    var target : NSObject!
    var keyPath : String!
    var nilValue : AnyObject!
    
    init(_ target: NSObject!, _ keyPath: String, nilValue: AnyObject? = nil) {
        self.target = target
        self.keyPath = keyPath
        self.nilValue = nilValue
    }
    
    func assignSignal(signal : RACSignal) {
        signal.setKeyPath(self.keyPath, onObject: self.target, nilValue: self.nilValue)
    }
}

extension NSObject {
    func RACObserve(target: NSObject!,_ keyPath: String) -> RACSignal{
        return target.rac_valuesForKeyPath(keyPath, observer: self)
    }
}


infix operator <~ {}
func <~ (rac: RAC, signal: RACSignal) {
    rac.assignSignal(signal)
}

infix operator ~> {}
func ~> (signal: RACSignal, rac: RAC) {
    rac.assignSignal(signal)
}

